package dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import util.Time;
import util.db.MsSqlConn;
import factory.AkimimiLineItemFactory;

public class AkimimiLineItem {

	public static List<AkimimiLineItemFactory> getAkimimiLineItem(int orderid)
	{
		List<AkimimiLineItemFactory> ItemList = new ArrayList<AkimimiLineItemFactory>();
		String sql = "select * from line_items where order_id=" + orderid + " ";
		
		MsSqlConn mssqlConn = new MsSqlConn();
		ResultSet rs = mssqlConn.executeQuery(sql);
		
		AkimimiLineItemFactory order = null;
		
		int id = 0;
		int order_id = 0;
		String user_id = "";
		String product_code = "";
		String product_title = "";
		String product_type_name = "";
		String supply_id = "";
		int price = 0;
		int quantity = 0;
		int product_cost = 0;
		String create_time = "";
		String update_id = "";
		String update_time = "";
		int invoice = 0;
		int tax = 0;
		String express_company = "";
		String express_info = "";
		
		try{
			while(rs.next())
			{
				id = rs.getInt("id");
				order_id = rs.getInt("order_id");
				user_id = rs.getString("user_id");
				product_code = rs.getString("product_code");
				product_title = rs.getString("product_title");
				product_type_name = rs.getString("product_type_name");
				supply_id = rs.getString("supply_id");
				price = rs.getInt("price");
				quantity = rs.getInt("quantity");
				product_cost = rs.getInt("product_cost");
				create_time = rs.getString("create_time");
				update_id = rs.getString("update_id");
				update_time= rs.getString("update_time");
				invoice = rs.getInt("invoice");
				tax = rs.getInt("tax");
				express_company = rs.getString("express_company");
				express_info = rs.getString("express_info");
				
				order = new AkimimiLineItemFactory(id, order_id, user_id, product_code, product_title, product_type_name,
						supply_id, price, quantity, product_cost, create_time, update_id, update_time, invoice, tax,
						express_company, express_info);
				
				ItemList.add(order);
			}	
		}catch(SQLException e){
			e.getStackTrace();
		}
		
		mssqlConn.closeConn();
		
		System.out.println("[" + Time.nowTime() + "]: " + sql);
		
		return ItemList;
	}
}

